package cn.gaotu.basic.service.impl;

import cn.gaotu.basic.mapper.BaseMapper;
import cn.gaotu.basic.query.BaseQuery;
import cn.gaotu.basic.service.BaseService;
import cn.gaotu.basic.util.PageList;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * @author ZouX
 * @date 2022/8/11 19:23
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//开始事务,设置为只读,后面为有事务执行,没有事务就不执行创建
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public void DeleteDep(Long id) {
        baseMapper.DeleteDep(id);
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer integer = baseMapper.queryCount(baseQuery);
        if (integer == null) {
            return new PageList<>();
        }
        //实现页面的分页数据
        List<T> list = baseMapper.queryData(baseQuery);
        return new PageList<>(list, integer);
    }

    @Override
    public void patchRemove(List<Long> ids) {
        baseMapper.patchRemove(ids);
    }


}
